package icu.xlg;

public class Television {
    private Power power;
    private Status status;
    private Ad ad;

    public Television(Power power) {
        this.power = power;
        status = Status.OFF;
    }

    public Television(Status status) {
        this.power = new Power(true);
        this.ad = new Ad();
        this.status = status;
    }

    public Television(Status status, Ad ad) {
        this.power = new Power(true);
        this.ad = ad;
        this.status = status;
    }

    public boolean turnOn() {
        //...其他业务逻辑
        //...corner case
        if (!power.isConnected()) {
            return false;
        }
        status = Status.ON;
        ad.show();
        return true;
    }

    public boolean turnOff() {
        //...其他业务逻辑
        //...corner case
        //重构代码
        return true;
    }

    private void showAd() {
        System.out.println("广告播放中...");
    }

    public boolean hibernate() {
        if (status == Status.ON) {
            status = Status.HIBERNATED;
            return true;
        }
        return false;
    }

    public boolean wakeUp() {
        if (status == Status.HIBERNATED) {
            status = Status.ON;
            ad.show();
            return true;
        }
        return false;
    }
}
